package cn.chi.base.service.impl;


import cn.chi.base.mapper.BaseMapper;
import cn.chi.base.query.BaseQuery;
import cn.chi.base.service.IBaseService;
import cn.chi.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public T queryById(Long id) {
        return (T) baseMapper.queryById(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }

    @Override
    public PageInfo<T> queryPage(BaseQuery query) {
        //查询总条数
        Long count = baseMapper.count(query);
        List<T> list = baseMapper.queryDate(query);
        return new PageInfo<>(count,list);
    }
}
